package android.db;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Rusiru Boteju
 */
public interface MethodsList {

    // ------------------------------------------------------------------------
    // "Connection Handling"
    // ------------------------------------------------------------------------
    /**
     * Ping HashDB
     * @return true (unless not authorized)
     * @throws Exception (as of ver. 0.09) in case of unauthorized access
     */
//    public HashDB ping() throws Exception;
    /**
     * Disconnects the client.
     * @HashDB QUIT
     */
    public void quit();

    // ------------------------------------------------------------------------
    // "Commands operating on string values"
    // ------------------------------------------------------------------------
    /**
     * Bind the value to key.
     * @HashDB SET
     * @param key any UTF-8 {@link String}
     * @param value any bytes.  For current data size limitations, refer to
     * HashDB documentation.
     * @throws Exception on user error.
     * @throws ProviderException on un-documented features/bug
     * @throws ClientRuntimeException on errors due to operating environment (HashDB or network)
     */
    //  public void set(String key, byte[] value) throws Exception;
    /**
     * Convenient method for {@link String} data binding
     * @HashDB SET
     * @param key
     * @param stringValue
     * @throws Exception
     * @see {@link HashDB#set(String, byte[])}
     */
    public void set(String key, String stringValue) throws Exception;

    /**
     * Convenient method for {@link String} numeric values binding
     * @HashDB SET
     * @param key
     * @param numberValue
     * @throws Exception
     * @see {@link HashDB#set(String, byte[])}
     */
    //public void set(String key, Number numberValue) throws Exception;
    /**
     * Binds the given java {@link Object} to the key.  Serialization format is
     * implementation specific.  Simple implementations may apply the basic {@link Serializable}
     * protocol.
     * @HashDB SET
     * @param <T>
     * @param key
     * @param object
     * @throws Exception
     * @see {@link HashDB#set(String, byte[])}
     */
    //public <T extends Serializable> void set(String key, T object) throws Exception;
    /**
     * @HashDB SETNX
     * @param key
     * @param value
     * @return
     * @throws Exception
     */
//    public boolean setnx(String key, byte[] value) throws Exception;
//
//    public boolean setnx(String key, String stringValue) throws Exception;
//
//    public boolean setnx(String key, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean setnx(String key, T object) throws Exception;
    /**
     * @HashDB GET
     * @param key
     * @return
     * @throws Exception
     */
    public String get(String key) throws Exception;

//    public byte[] getset(String key, byte[] value) throws Exception;
    public String getset(String key, String stringValue) throws Exception;

    //public Object getset(String key, Number numberValue) throws Exception;
    //  public <T extends Serializable> byte[] getset(String key, T object) throws Exception;
    /**
     * @HashDB MGET
     * @param key
     * @param moreKeys
     * @return
     * @throws Exception
     */
    //public List<byte[]> mget(String... keys) throws Exception;
    /**
     * @HashDB INCR
     * @param key
     * @return
     * @throws Exception
     */
    public long incr(String key) throws Exception;

    /**
     * @HashDB INCRBY
     * @param key
     * @param delta
     * @return
     * @throws Exception
     */
    public long incrby(String key, int delta) throws Exception;

    /**
     * @HashDB DECR
     * @param key
     * @return
     * @throws Exception
     */
    public long decr(String key) throws Exception;

    /**
     * @HashDB DECRBY
     * @param key
     * @param delta
     * @return
     * @throws Exception
     */
    public long decrby(String key, int delta) throws Exception;

    /**
     * @HashDB EXISTS
     * @param key
     * @return
     * @throws Exception
     */
    public boolean exists(String key) throws Exception;

    /**
     * @HashDB DEL
     * @param keys one or more non-null, non-zero-length, keys to be deleted
     * @return number of keys actually deleted
     * @throws Exception
     */
    public long del(String... keys) throws Exception;
    public boolean del(String key) throws Exception;
    // ------------------------------------------------------------------------
    // "Commands operating on the key space"
    // ------------------------------------------------------------------------

    /**
     * @HashDB KEYS
     * @param pattern
     * @return
     * @throws Exception
     */
    public List<String> keys(String pattern) throws Exception;

    /**
     * Convenience method.  Equivalent to calling <code>jredis.keys("*");</code>
     * @HashDB KEYS
     * @return
     * @throws Exception
     * @see {@link HashDB#keys(String)}
     */
    public List<String> keys() throws Exception;

    /**
     * @HashDB RANDOMKEY
     * @return
     * @throws Exception
     */
    //public String randomkey() throws Exception;
    /**
     * @HashDB RENAME
     * @param oldkey
     * @param newkey
     * @throws Exception
     */
    public boolean rename(String oldkey, String newkey) throws Exception;

    /**
     * @HashDB RENAMENX
     * @param oldkey
     * @param brandnewkey
     * @return
     * @throws Exception
     */
    //public boolean renamenx(String oldkey, String brandnewkey) throws Exception;
    /**
     * @HashDB DBSIZE
     * @return
     * @throws Exception
     */
    public long dbsize() throws Exception;

    /**
     * @HashDB MERGEDB
     * @return
     * @param Hashtable ht
     * @throws Exception
     */
    public void mergeDb(Hashtable ht) throws Exception;

    // ------------------------------------------------------------------------
    // Commands operating on lists
    // ------------------------------------------------------------------------
    /**
     * @HashDB RPUSH
     * @param listkey
     * @param value
     * @throws Exception
     */
//    public void rpush(String listkey, byte[] value) throws Exception;
//
//    public void rpush(String listkey, String stringValue) throws Exception;
//
//    public void rpush(String listkey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> void rpush(String listkey, T object) throws Exception;
    /**
     * @HashDB LPUSH
     * @param listkey
     * @param value
     * @throws Exception
     */
//    public void lpush(String listkey, byte[] value) throws Exception;
//
//    public void lpush(String listkey, String stringValue) throws Exception;
//
//    public void lpush(String listkey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> void lpush(String listkey, T object) throws Exception;
    /**
     * @HashDB LSET
     * @param key
     * @param index
     * @param value
     * @throws Exception
     */
//    public void lset(String key, long index, byte[] value) throws Exception;
//
//    public void lset(String key, long index, String stringValue) throws Exception;
//
//    public void lset(String key, long index, Number numberValue) throws Exception;
//
//    public <T extends Serializable> void lset(String key, long index, T object) throws Exception;
//
//    /**
//     * @HashDB LREM
//     * @param listKey
//     * @param value
//     * @param count
//     * @return
//     * @throws Exception
//     */
//    public long lrem(String listKey, byte[] value, int count) throws Exception;
//
//    public long lrem(String listKey, String stringValue, int count) throws Exception;
//
//    public long lrem(String listKey, Number numberValue, int count) throws Exception;
//
//    public <T extends Serializable> long lrem(String listKey, T object, int count) throws Exception;
//
//    /**
//     * Given a 'list' key, returns the number of items in the list.
//     * @HashDB LLEN
//     * @param listkey
//     * @return
//     * @throws Exception
//     */
//    public long llen(String listkey) throws Exception;
//
//    /**
//     * @HashDB LRANGE
//     * @param listkey
//     * @param from
//     * @param to
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> lrange(String listkey, long from, long to) throws Exception;
//
//    /**
//     * @HashDB LTRIM
//     * @param listkey
//     * @param keepFrom
//     * @param keepTo
//     * @throws Exception
//     */
//    public void ltrim(String listkey, long keepFrom, long keepTo) throws Exception;
//
//    /**
//     * @HashDB LINDEX
//     * @param listkey
//     * @param index
//     * @return
//     * @throws Exception
//     */
//    public byte[] lindex(String listkey, long index) throws Exception;
//
//    /**
//     * @HashDB LPOP
//     * @param listKey
//     * @return
//     * @throws Exception
//     */
//    public byte[] lpop(String listKey) throws Exception;
//
//    /**
//     * @HashDB RPOP
//     * @param listKey
//     * @return
//     * @throws Exception
//     */
//    public byte[] rpop(String listKey) throws Exception;
//
//    /**
//     * @HashDB RPOPLPUSH
//     * @param srcList
//     * @param destList
//     * @return
//     * @throws Exception
//     */
//    public byte[] rpoplpush(String srcList, String destList) throws Exception;
//
//    // ------------------------------------------------------------------------
//    // Commands operating on sets
//    // ------------------------------------------------------------------------
//    /**
//     * @HashDB SADD
//     * @param setkey
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public boolean sadd(String setkey, byte[] member) throws Exception;
//
//    public boolean sadd(String setkey, String stringValue) throws Exception;
//
//    public boolean sadd(String setkey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean sadd(String setkey, T object) throws Exception;
//
//    /**
//     * @HashDB SREM
//     * @param setKey
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public boolean srem(String setKey, byte[] member) throws Exception;
//
//    public boolean srem(String setKey, String stringValue) throws Exception;
//
//    public boolean srem(String setKey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean srem(String setKey, T object) throws Exception;
//
//    /**
//     * @HashDB SISMEMBER
//     * @param setKey
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public boolean sismember(String setKey, byte[] member) throws Exception;
//
//    public boolean sismember(String setKey, String stringValue) throws Exception;
//
//    public boolean sismember(String setKey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean sismember(String setKey, T object) throws Exception;
//
//    /**
//     * @HashDB SMOVE
//     * @param srcKey
//     * @param destKey
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public boolean smove(String srcKey, String destKey, byte[] member) throws Exception;
//
//    public boolean smove(String srcKey, String destKey, String stringValue) throws Exception;
//
//    public boolean smove(String srcKey, String destKey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean smove(String srcKey, String destKey, T object) throws Exception;
//
//    /**
//     * @HashDB SCARD
//     * @param setKey
//     * @return
//     * @throws Exception
//     */
//    public long scard(String setKey) throws Exception;
//
//    /**
//     * @HashDB SINTER
//     * @param set1
//     * @param sets
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> sinter(String set1, String... sets) throws Exception;
//
//    /**
//     * @HashDB SINTERSTORE
//     * @param destSetKey
//     * @param sets
//     * @throws Exception
//     */
//    public void sinterstore(String destSetKey, String... sets) throws Exception;
//
//    /**
//     * @HashDB SUNION
//     * @param set1
//     * @param sets
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> sunion(String set1, String... sets) throws Exception;
//
//    /**
//     * @HashDB SUNIONSTORE
//     * @param destSetKey
//     * @param sets
//     * @throws Exception
//     */
//    public void sunionstore(String destSetKey, String... sets) throws Exception;
//
//    /**
//     * @HashDB SDIFF
//     * @param set1
//     * @param sets
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> sdiff(String set1, String... sets) throws Exception;
//
//    /**
//     * @HashDB SDIFFSTORE
//     * @param destSetKey
//     * @param sets
//     * @throws Exception
//     */
//    public void sdiffstore(String destSetKey, String... sets) throws Exception;
//
//    /**
//     * @HashDB SMEMBERS
//     * @param setkey
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> smembers(String setkey) throws Exception;
//
//    /**
//     * @HashDB SRANDMEMBER
//     * @param setkey
//     * @return
//     * @throws Exception
//     */
//    public byte[] srandmember(String setkey) throws Exception;
//
//    /**
//     * @HashDB SPOP
//     * @param setkey
//     * @return
//     * @throws Exception
//     */
//    public byte[] spop(String setkey) throws Exception;
//
//    // ------------------------------------------------------------------------
//    // Commands operating on sets
//    // ------------------------------------------------------------------------
//    /**
//     * @HashDB ZADD
//     * @param setkey
//     * @param score
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public boolean zadd(String setkey, double score, byte[] member) throws Exception;
//
//    public boolean zadd(String setkey, double score, String stringValue) throws Exception;
//
//    public boolean zadd(String setkey, double score, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean zadd(String setkey, double score, T object) throws Exception;
//
//    /**
//     * @HashDB ZREM
//     * @param setKey
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public boolean zrem(String setKey, byte[] member) throws Exception;
//
//    public boolean zrem(String setKey, String stringValue) throws Exception;
//
//    public boolean zrem(String setKey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> boolean zrem(String setKey, T object) throws Exception;
//
//    /**
//     * @HashDB ZCARD
//     * @param setKey
//     * @return
//     * @throws Exception
//     */
//    public long zcard(String setKey) throws Exception;
//
//    /**
//     * @HashDB ZCOUNT
//     * @param setkey
//     * @param minScore
//     * @param maxScore
//     * @return
//     * @throws Exception
//     */
//    public long zcount(String setkey, double minScore, double maxScore) throws Exception;
//
//    /**
//     * @HashDB ZSCORE
//     * @param setkey
//     * @param member
//     * @return
//     * @throws Exception
//     */
//    public Double zscore(String setkey, byte[] member) throws Exception;
//
//    public Double zscore(String setkey, String stringValue) throws Exception;
//
//    public Double zscore(String setkey, Number numberValue) throws Exception;
//
//    public <T extends Serializable> Double zscore(String setkey, T object) throws Exception;
//
//    /**
//     * @HashDB ZRANGE
//     * @param setkey
//     * @param from
//     * @param to
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> zrange(String setkey, long from, long to) throws Exception;
//
//    /**
//     * @HashDB ZREVRANGE
//     * @param setkey
//     * @param from
//     * @param to
//     * @return
//     * @throws Exception
//     */
//    public List<byte[]> zrevrange(String setkey, long from, long to) throws Exception;
    // ------------------------------------------------------------------------
    // Multiple databases handling commands
    // ------------------------------------------------------------------------
//	@Deprecated
//	public HashDB select (int index) throws Exception;
    /**
     * Flushes the db you selected when connecting to HashDB server.  Typically,
     * implementations will select db 0 on connecting if non was specified.  Remember
     * that there is no roll-back.
     * @HashDB FLUSHDB
     * @return
     * @throws Exception
     */
    public HashDB flushdb() throws Exception;

    /**
     * Flushes all dbs in the connect HashDB server, regardless of which db was selected
     * on connect time.  Remember that there is no rollback.
     * @HashDB FLUSHALL
     * @return
     * @throws Exception
     */
    public HashDB flushall() throws Exception;

    /**
     * Moves the given key from the currently selected db to the one indicated
     * by <code>dbIndex</code>.
     * @HashDB MOVE
     * @param key
     * @param dbIndex
     * @return
     * @throws Exception
     */
    public boolean move(String key, int dbIndex) throws Exception;
    // ------------------------------------------------------------------------
    // Sorting
    // ------------------------------------------------------------------------
    /**
     * Usage:
     * <p>Usage:
     * <p><code><pre>
     * List<byte[]>  results = HashDB.sort("my-list-or-set-key").BY("weight*").
     * LIMIT(1, 11).GET("object*").DESC().ALPHA().exec();
     * for(byte[] item : results) {
     *     // do something with item ..
     *  }
     * </pre></code>
     * <p>Sort specification elements are all options.  You could simply say:
     * <p><code><pre>
     * List<byte[]>  results = HashDB.sort("my-list-or-set-key").exec();
     * for(byte[] item : results) {
     *     // do something with item ..
     *  }
     * </pre></code>
     * <p>Sort specification elements are also can appear in any order --
     * the client implementation will send them to the server
     * in the order expected by the protocol, although it is good form to specify the predicates in natural order:
     * <p><code><pre>
     * List<byte[]>  results = HashDB.sort("my-list-or-set-key").GET("object*").
     * DESC().ALPHA().BY("weight*").LIMIT(1, 11).exec();
     * for(byte[] item : results) {
     *     // do something with item ..
     *  }
     * </pre></code>
     *
     * @HashDB SORT
     */
    //public Sort sort(String key);
    // ------------------------------------------------------------------------
    // Persistence control commands
    // ------------------------------------------------------------------------
    /**
     * @HashDB SAVE
     * @throws Exception
     */
//    public void save() throws Exception;
//
//    /**
//     * @HashDB BGSAVE
//     * @throws Exception
//     */
//    public void bgsave() throws Exception;
//
//    /**
//     * @HashDB BGREWRITEAOF
//     * @return ack message.
//     * @throws Exception
//     */
//    public String bgrewriteaof() throws Exception;
//
//    /**
//     * @HashDB LASTSAVE
//     * @return
//     * @throws Exception
//     */
//    public long lastsave() throws Exception;
//
////	@Deprecated
////	public void shutdown () throws Exception;
//// ------------------------------------------------------------------------
//// Remote server control commands
//// ------------------------------------------------------------------------
//    /**
//     * @HashDB INFO
//     * @return
//     * @throws Exception
//     */
//    public Map<String, String> info() throws Exception;
//
//    /**
//     * @HashDB SLAVEOF
//     * @param host ip address
//     * @param port
//     */
//    public void slaveof(String host, int port) throws Exception;
//
//    /**
//     * Convenience method.  Turns off replication.
//     * @HashDB SLAVEOF "no one"
//     */
//    public void slaveofnone() throws Exception;
//
//    // ------------------------------------------------------------------------
//    // Diagnostics commands
//    // ------------------------------------------------------------------------
//    /**
//     * @HashDB ECHO
//     * @param msg
//     * @return
//     * @throws Exception
//     */
//    public byte[] echo(byte[] msg) throws Exception;
//
//    public byte[] echo(String msg) throws Exception;
//
//    public byte[] echo(Number msg) throws Exception;
//
//    public <T extends Serializable> byte[] echo(T msg) throws Exception;
}
